package com.project.netmodule.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.WindowManager;
import com.utils.module.ScreenUtils;

/**
 * Created by Administrator on 2016/5/13.
 */
public class NetDialogUtil {
    private  Context context;
    private  AlertDialog ad ;
    public void initDialog(Context context, int res , ContentViewListener listener) {
        // TODO Auto-generated constructor stub
        this.context=context;
        View view = View.inflate(context,res,null) ;
        if ( listener != null)
            listener.onViewInit(view);
//        GifMovieView gifView = (GifMovieView) view.findViewById(R.id.gif_view);
//        if ( gifView!=null)
//            gifView.setMovieResource(R.drawable.loading_big);
        ad=new AlertDialog.Builder(context).create();
        ad.setCanceledOnTouchOutside(false);
        ad.setView(view);
        //解决黑色棱角问题
        ad.getWindow().setBackgroundDrawable(new BitmapDrawable());
    }

    public void show(){
        if( ad.isShowing() ){
            return;
        }
        ad.show();
        WindowManager.LayoutParams params =
                ad.getWindow().getAttributes();
        params.width = ScreenUtils.getScreenWidth(context)*3/5;
        params.height = ScreenUtils.getScreenHeight(context)/5 ;
        ad.getWindow().setAttributes(params);
    }

    public void dismiss(){
        if( ad != null  && ad.isShowing() ){
            ad.dismiss();
        }
    }

    public interface ContentViewListener extends View.OnClickListener {
        public void onViewInit(View contentView) ;
    }
}
